package L0705;

import java.util.Scanner;

public class L02 {
    public static long sqrt(int num){
        if(num==0||num==1)
            return num;
        long start=1;
        long end=num;
        long result=0;

        while(start<end){
            long mid=(start+end)/2;
            long square=num/mid;
            if(mid==square)return mid;
            else if (mid<square) {
                //start与end相邻时，应该跳出循环，设置一个-1
                end=mid-1;
            }else {//由于是向下取整，所以仅当小于num的情况才可以
                start=mid+1;
                result=mid;
            }
        }
        return result;
    }
    public static void main (String[] args) {
        Scanner p=new Scanner (System.in);
        System.out.print("请输入：");
        int num=p.nextInt ();
        System.out.println (sqrt(num));
    }
}
